<form class="form-horizontal" id="winModal">
    <input id="id" name="id" type="hidden">
    <div class="form-group">
        <label class="col-sm-3 control-label text-left">用户昵称：</label>
        <div class="col-sm-8">
            <input id="nickName" name="nickName" class="form-control" type="text" placeholder="请输入用户昵称">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label text-left">登陆账号：</label>
        <div class="col-sm-8">
            <input id="userName" name="userName" class="form-control" type="text" placeholder="请输入登陆账号">
        </div>
    </div>
    <div class="form-group myPassword" style="display: none">
        <label class="col-sm-3 control-label text-left">账号密码：</label>
        <div class="col-sm-8">
            <input id="password" name="password" class="form-control" type="password"
                   placeholder="请输入账号密码，新增无密码默认123456" disabled="disabled" readonly="readonly">
        </div>
    </div>
    <div class="form-group myPassword" style="display: none">
        <label class="col-sm-3 control-label text-left">确认密码：</label>
        <div class="col-sm-8">
            <input id="confirm_password" name="confirm_password" class="form-control" type="password"
                   placeholder="请再次输入确认密码，编辑不输入不更改" disabled="disabled" readonly="readonly">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label text-left">账号排序：</label>
        <div class="col-sm-8">
            <input id="sort" name="sort" class="form-control" type="number" value="0" min="0" placeholder="请输入排序编号">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label text-left">角色权限：</label>
        <div class="col-sm-8">
            <select class="form-control roleId selectpicker" id="roleId" name="roleId"></select>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(function () {
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#winModal").validate({
            rules: {           //定义验证规则,其中属性名为表单的name属性
                nickName: {
                    required: true,
                    // ignore: ".ignore",//忽略不验证
                    rangelength: [2, 12],
                    stringAllName: true,
                    remote: {
                        url: "check.json",
                        type: "post",
                        data: {
                            nickName: function () {
                                return $("#nickName").val();
                            },
                            id: function () {
                                return $("#id").val();
                            }
                        }
                    }
                },
                userName: {
                    required: true,
                    //  ignore: ".ignore",//忽略不验证
                    rangelength: [2, 12],
                    stringEnName: true,
                    remote: {
                        url: "check.json",
                        type: "post",
                        data: {
                            userName: function () {
                                return $("#userName").val();
                            },
                            id: function () {
                                return $("#id").val();
                            }
                        }
                    }
                },
                password: {
                    required: function () {
                        if ($('#password').val() == null || $('#password').val() == undefined || $('#password').val() == "") {
                            return false;
                        } else {
                            return true;
                        }
                    },
                    minlength: 6,
                    stringPassWord: true,
                },
                confirm_password: {
                    required: function () {
                        if ($('#password').val() == null || $('#password').val() == undefined || $('#password').val() == "") {
                            return false;
                        } else {
                            return true;
                        }
                    },
                    equalTo: "#password"
                },
                roleId: {
                    required: true,
                    digits: true,
                    minlength: 1
                },
                sort: {
                    required: true,
                    digits: true
                }
            },
            messages: {       //自定义验证消息
                nickName: {
                    required: e + "请输入账号",
                    stringNickName: e + "只能包括中文、英文、数字和下划线，数字和下划线不能开头",
                    rangelength: $.validator.format(e + "账号位数要在{0}-{1}个字符之间。"),
                    remote: $.validator.format(e + "用户昵称“{0}”已经被占用。")
                },
                userName: {
                    required: e + "请输入登陆账号",
                    stringUserName: e + "只能包括英文、数字和下划线，下划线不能开头",
                    rangelength: $.validator.format(e + "登陆账号位数要在{0}-{1}个字符之间。"),
                    remote: $.validator.format(e + "登陆账号“{0}”已经被占用。")
                },
                password: {
                    required: e + "请再次输入密码",
                    stringPassWord: e + "只能包括英文、数字和下划线，下划线不能开头",
                    rangelength: $.validator.format(e + "密码位数最低为{0}个字符。")
                },
                confirm_password: {
                    required: e + "请输入确认密码",
                    equalTo: e + "密码验证需要与密码一致"
                },
                roleId: {
                    required: e + "请选择用户角色"
                },
                sort: {
                    required: e + "排序编号不正确，只允许为正整数"
                }
            },
        });

    });
</script>